//
//  IntegralListCell.m
//  BXlive
//
//  Created by bxlive on 2017/5/18.
//  Copyright © 2017年 cat. All rights reserved.
//

#import "IntegralListCell.h"
#import <SLDeveloperTools/SLDeveloperTools.h>
#import <SDAutoLayout/SDAutoLayout.h>

@interface IntegralListCell()
@property (nonatomic , strong) UIImageView *headImageView;//头像
@property (nonatomic , strong) UILabel * nickNameLabel;//昵称
@property (nonatomic , strong) UILabel * signatureLabel;//个性签名
@property (nonatomic , strong) UILabel *timeLabel;//时间
@end

@implementation IntegralListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    IntegralListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IntegralListCell"];
    
    if (cell == nil) {
        cell = [[IntegralListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"IntegralListCell"];
    }
    
    return cell;
}

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setupUI];
    }
    return self;
}

/**
 *  初始化控件
 */
- (void) setupUI{
    
    self.headImageView = [UIImageView new];
    
    self.nickNameLabel = [UILabel initWithFrame:CGRectZero size:15 color:MainTitleColor alignment:0 lines:1];
    self.signatureLabel =[UILabel initWithFrame:CGRectZero size:12 color:MinorColor alignment:0 lines:1];
    self.timeLabel =[UILabel initWithFrame:CGRectZero size:13 color:MinorColor alignment:0 lines:1];
    UIView *fengeView = [[UIView alloc]initWithFrame:CGRectZero];
    fengeView.backgroundColor = LineNormalColor;
    
    [self.contentView sd_addSubviews:@[self.headImageView,self.nickNameLabel,self.signatureLabel,self.timeLabel,fengeView]];
    self.headImageView.sd_layout.leftSpaceToView(self.contentView, 16).centerYEqualToView(self.contentView).widthIs(40).heightEqualToWidth();
    self.headImageView.sd_cornerRadius = @(self.headImageView.width/2);
    self.timeLabel.sd_layout.rightSpaceToView(self.contentView, 10).topSpaceToView(self.contentView, 10).heightIs(20);
    [self.timeLabel setSingleLineAutoResizeWithMaxWidth:100.f];
    self.nickNameLabel.sd_layout.leftSpaceToView(self.headImageView, 15).topSpaceToView(self.contentView, 8).heightIs(20).rightSpaceToView(self.timeLabel, 5);
    self.signatureLabel.sd_layout.leftSpaceToView(self.headImageView, 15).rightSpaceToView(self.timeLabel, 5).topSpaceToView(self.nickNameLabel, 0).heightIs(20);
   fengeView.sd_layout.leftSpaceToView(self.contentView, 15).bottomSpaceToView(self.contentView, 0).rightSpaceToView(self.contentView, 0).heightIs(0.5);
}

-(void)setModel:(IntegralListModel *)model{
    
    [self.headImageView zzl_setImageWithURLString:[NSURL URLWithString:model.avatar] placeholder:[UIImage imageNamed:@"placeplaceholder"]];
    self.nickNameLabel.text = model.nickname;
    self.signatureLabel.text = model.sign;
    self.timeLabel.text = model.create_time;
   
}

-(NSString *)time:(NSString *)timeStirng{
    NSTimeInterval time=[timeStirng doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    NSLog(@"date:%@",[detaildate description]);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    return currentDateStr;
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
